package com.nci.cloud.unit.management.FilePivotServerByProtoBuf;

import com.nci.cloud.unit.management.ProtoBufFileTrans.FileRecvUtils;
import com.nci.cloud.unit.management.message.Message;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class ProtoBufServerHandler extends ChannelInboundHandlerAdapter {

    FileRecvUtils fileRecvUtils = new FileRecvUtils("d:\\");
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        Message.TransRequest req = (Message.TransRequest) msg;

        Message.commandType command = req.getCommand();
        if(command.equals(Message.commandType.upload)){
            fileRecvUtils.recvFile(req);
        }// upload
    }


    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        cause.printStackTrace();
        ctx.close();
    }

}
